package com.sjx.boundarycallback.room;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.sjx.boundarycallback.api.User;
import com.sjx.boundarycallback.dao.UserDao;


/**
 * 创建Room数据库
 */
@Database(entities = {User.class}, version = 1, exportSchema = false)
public abstract class UserDataBase extends RoomDatabase {

    private static final String DATABASE_NAME = "user_db";

    private static UserDataBase databaseInstance;

    public static synchronized UserDataBase getInstance(Context context) {
        if (databaseInstance == null) {
            databaseInstance = Room.databaseBuilder(
                    context.getApplicationContext(),
                    UserDataBase.class,
                    DATABASE_NAME
            ).build();
        }

        return databaseInstance;

    }

    public abstract UserDao userDao();

}
